GameManager = GameManager or Class("GameManager", EventDispatcher)
GameEvent = RegisterEvents{ "Reload" }
---@diagnostic disable-next-line: duplicate-set-field
function GameManager:ctor()
    EventDispatcher.ctor(self)
    self.gameName = "helloWorld"
    self.dataManager = DataManager.new()
end

function GameManager:load(gameName)
    local file, err = io.open("games/"..gameName..".json", "r")
    if not file then
        Console.error("GameManager:load", err)
        return
    end
    local content = file:read("*a")
    file:close()
    local game = Json.decode(content)
    self.gameName = game.name
    self.dataManager:fromJson(game.data)
    self:emit(GameEvent.Reload)
end

function GameManager:Save()
    local file, err = io.open("games/"..self.gameName..".json", "w")
    local game = {}
    game.data = self.dataManager:getSaveData()
    game.name = self.gameName
    file:write(Json.encode(game))
    file:close()
end